<!DOCTYPE HTML>
<html lang="zh-CN">

<head><meta name="generator" content="Hexo 3.9.0">
    <!--Setting-->
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="IE=Edge,chrome=1">
    <meta http-equiv="Cache-Control" content="no-siteapp">
    <meta http-equiv="Cache-Control" content="no-transform">
    <meta name="renderer" content="webkit|ie-comp|ie-stand">
    <meta name="apple-mobile-web-app-capable" content="ydong博客">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">
    <meta name="format-detection" content="telephone=no,email=no,adress=no">
    <meta name="browsermode" content="application">
    <meta name="screen-orientation" content="portrait">
    <meta name="theme-version" content="1.2.3">
    <meta name="root" content="/blog/">
    <link rel="dns-prefetch" href="http://ydongabc.gitee.io/blog">
    <!--SEO-->

<meta name="keywords" content="弹性布局,flex">


<meta name="description" content="弹性布局，又称“Flex布局”，可以简便、完整、响应式地实现各种页面布局。采用Flex布局的元素，称为Flex容器（flex container），简称”容器”。它的所有子元素自动成为容器成员，...">


<meta name="robots" content="all">
<meta name="google" content="all">
<meta name="googlebot" content="all">
<meta name="verify" content="all">
    <!--Title-->

<title>
    
    弹性布局flex |
    
    ydong博客
</title>

<link rel="alternate" href="/atom.xml" title="ydong博客" type="application/atom+xml">


<link rel="icon" href="./favicon.ico">

    

<link rel="stylesheet" href="/blog/css/bootstrap.min.css?rev=3.3.7">
<link rel="stylesheet" href="/blog/css/font-awesome.min.css?rev=4.7.0">
<link rel="stylesheet" href="/blog/css/style.css?rev=@@hash">
    
<div class="hide">
    <script type="text/javascript">
    var cnzz_protocol = (("https:" == document.location.protocol) ? " https://" : " http://");
    document.write(unescape("%3Cspan class='cnzz_stat_icon_1263868967 hide' %3E%3Cscript%20src%3D%22https%3A%2F%2Fs95.cnzz.com%2Fz_stat.php%3Fweb_id%3D1272564536%22%3E%3C%2Fscript%3E%3C/span%3E%3Cscript src='" + cnzz_protocol + "s19.cnzz.com/z_stat.php%3Fid%3D1263868967%26show%3Dpic1' type='text/javascript'%3E%3C/script%3E"));
    </script>
</div>




    

</head></html>
<!--[if lte IE 8]>
<style>
    html{ font-size: 1em }
</style>
<![endif]-->
<!--[if lte IE 9]>
<div style="ie">你使用的浏览器版本过低，为了你更好的阅读体验，请更新浏览器的版本或者使用其他现代浏览器，比如Chrome、Firefox、Safari等。</div>
<![endif]-->
<body>
    <header class="main-header"  style="background-image:url(
    /blog/./img/banner.jpg)"
     >
    <div class="main-header-box">
        <a class="header-avatar" href="/" title='John Doe'>
            <img src="/blog/img/avatar.jpg" alt="logo头像" class="img-responsive center-block">
        </a>
        <div class="branding">
            <!--<h2 class="text-hide">Snippet主题,从未如此简单有趣</h2>-->
            
            <img src="/blog/img/branding.png" alt="Snippet 博客主题" class="img-responsive center-block">
            
        </div>
    </div>
</header>
    <nav class="main-navigation">
    <div class="container">
        <div class="row">
            <div class="col-sm-12">
                <div class="navbar-header"><span class="nav-toggle-button collapsed pull-right" data-toggle="collapse" data-target="#main-menu" id="mnav">
                        <span class="sr-only"></span>
                        <i class="fa fa-bars"></i>
                    </span>
                    <a class="navbar-brand" href="http://ydongabc.gitee.io/blog">
                        ydong博客</a>
                </div>
                <div class="collapse navbar-collapse" id="main-menu">
                    <ul class="menu">
                        
                        <li role="presentation" class="text-center">
                            <a href="/blog"><i class="fa "></i>
                                首页</a>
                        </li>
                        
                        <li role="presentation" class="text-center">
                            <a href="/blog/categories/前端/"><i class="fa "></i>
                                前端</a>
                        </li>
                        
                        <li role="presentation" class="text-center">
                            <a href="/blog/categories/后端/"><i class="fa "></i>
                                后端</a>
                        </li>
                        
                        <li role="presentation" class="text-center">
                            <a href="/blog/categories/工具/"><i class="fa "></i>
                                工具</a>
                        </li>
                        
                        <li role="presentation" class="text-center">
                            <a href="/blog/archives/"><i class="fa "></i>
                                时间轴</a>
                        </li>
                        
                    </ul>
                </div>
            </div>
        </div>
    </div>
</nav>
    <section class="content-wrap">
        <div class="container">
            <div class="row">
                <main class="col-md-8 main-content m-post">
                    <p id="process"></p>
<article class="post">
    <div class="post-head">
        <h1 id="弹性布局flex">
            
            弹性布局flex
            
        </h1>
        <div class="post-meta">
    
    <span class="categories-meta fa-wrap">
        <i class="fa fa-folder-open-o"></i>
        <a class="category-link" href="/blog/categories/前端/">前端</a> <a class="category-link" href="/blog/categories/前端/css3/">css3</a>
    </span>
    
    
    <span class="fa-wrap">
        <i class="fa fa-tags"></i>
        <span class="tags-meta">
            
            <a class="tag-link" href="/blog/tags/flex/">flex</a> <a class="tag-link" href="/blog/tags/弹性布局/">弹性布局</a>
            
        </span>
    </span>
    
    
    
    <span class="fa-wrap">
        <i class="fa fa-clock-o"></i>
        <span class="date-meta">
            2019/10/02</span>
    </span>
    
    
</div>
        
        
    </div>
    
    <div class="post-body post-content">
        <p>弹性布局，又称“Flex布局”，可以简便、完整、响应式地实现各种页面布局。采用Flex布局的元素，称为Flex容器（flex container），简称”容器”。它的所有子元素自动成为容器成员，称为Flex项目(flex item)，简称”项目”<a id="more"></a>。<br>注：设为Flex布局以后，子元素的float、clear和vertical-align属性将失效。</p>
<h2 id="父容器属性"><a href="#父容器属性" class="headerlink" title="父容器属性"></a>父容器属性</h2><figure class="highlight css"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br></pre></td><td class="code"><pre><span class="line"><span class="selector-id">#fu-box</span>&#123;</span><br><span class="line">    <span class="attribute">display</span>: flex;</span><br><span class="line">    <span class="attribute">flex-flow</span>: row wrap;</span><br><span class="line">    <span class="attribute">justify-content</span>: flex-start;</span><br><span class="line">    <span class="attribute">align-items</span>: stretch;</span><br><span class="line">    <span class="attribute">align-content</span>: stretch;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<h3 id="flex-flow：主轴方向flex-direction和换行方式flex-wrap的缩写形式"><a href="#flex-flow：主轴方向flex-direction和换行方式flex-wrap的缩写形式" class="headerlink" title="flex-flow：主轴方向flex-direction和换行方式flex-wrap的缩写形式"></a>flex-flow：主轴方向flex-direction和换行方式flex-wrap的缩写形式</h3><table>
<thead>
<tr>
<th align="left">值</th>
<th align="left">描述</th>
</tr>
</thead>
<tbody><tr>
<td align="left">row</td>
<td align="left">主轴从左往右</td>
</tr>
<tr>
<td align="left">row-reverse</td>
<td align="left">主轴从右往左</td>
</tr>
<tr>
<td align="left">column</td>
<td align="left">主轴从上往下</td>
</tr>
<tr>
<td align="left">column-reverse</td>
<td align="left">主轴从下往上</td>
</tr>
<tr>
<td align="left">wrap</td>
<td align="left">子元素排满时换行</td>
</tr>
<tr>
<td align="left">nowrap</td>
<td align="left">子元素排满时挤压不换行</td>
</tr>
</tbody></table>
<h3 id="justify-content：主轴设置，即项目水平方向位置"><a href="#justify-content：主轴设置，即项目水平方向位置" class="headerlink" title="justify-content：主轴设置，即项目水平方向位置"></a>justify-content：主轴设置，即项目水平方向位置</h3><table>
<thead>
<tr>
<th align="left">值</th>
<th align="left">描述</th>
</tr>
</thead>
<tbody><tr>
<td align="left">flex-startp(默认值)</td>
<td align="left">项目位于主轴起点</td>
</tr>
<tr>
<td align="left">flex-end</td>
<td align="left">项目位于主轴终点</td>
</tr>
<tr>
<td align="left">center</td>
<td align="left">居中</td>
</tr>
<tr>
<td align="left">space-between</td>
<td align="left">两端贴边对齐，项目之间的间隔都相等</td>
</tr>
<tr>
<td align="left">space-around</td>
<td align="left">平均，每个项目两侧的间隔相等</td>
</tr>
</tbody></table>
<h3 id="align-items：侧轴设置，即项目垂直方向位置"><a href="#align-items：侧轴设置，即项目垂直方向位置" class="headerlink" title="align-items：侧轴设置，即项目垂直方向位置"></a>align-items：侧轴设置，即项目垂直方向位置</h3><table>
<thead>
<tr>
<th align="left">值</th>
<th align="left">描述</th>
</tr>
</thead>
<tbody><tr>
<td align="left">stretch(默认值)</td>
<td align="left">元素被拉伸以适应容器</td>
</tr>
<tr>
<td align="left">flex-startp</td>
<td align="left">项目位于侧轴起点</td>
</tr>
<tr>
<td align="left">flex-end</td>
<td align="left">项目位于侧轴终点</td>
</tr>
<tr>
<td align="left">center</td>
<td align="left">居中</td>
</tr>
<tr>
<td align="left">baseline</td>
<td align="left">与项目的第一行文字的基线对齐</td>
</tr>
</tbody></table>
<h3 id="align-content：当项目换为多行时，即用align-content取代align-items，值同-justify-content"><a href="#align-content：当项目换为多行时，即用align-content取代align-items，值同-justify-content" class="headerlink" title="align-content：当项目换为多行时，即用align-content取代align-items，值同 justify-content"></a>align-content：当项目换为多行时，即用align-content取代align-items，值同 justify-content</h3><table>
<thead>
<tr>
<th align="left">值</th>
<th align="left">描述</th>
</tr>
</thead>
<tbody><tr>
<td align="left">stretch(默认值)</td>
<td align="left">元素被拉伸以适应容器</td>
</tr>
<tr>
<td align="left">flex-startp</td>
<td align="left">项目位于侧轴起点</td>
</tr>
<tr>
<td align="left">flex-end</td>
<td align="left">项目位于侧轴终点</td>
</tr>
<tr>
<td align="left">center</td>
<td align="left">居中</td>
</tr>
<tr>
<td align="left">space-between</td>
<td align="left">两端贴边对齐，项目之间的间隔都相等</td>
</tr>
<tr>
<td align="left">space-around</td>
<td align="left">平均，每个项目两侧的间隔相等</td>
</tr>
</tbody></table>
<h2 id="子项目属性"><a href="#子项目属性" class="headerlink" title="子项目属性"></a>子项目属性</h2><figure class="highlight css"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line"><span class="selector-class">.zi</span>&#123;</span><br><span class="line">    <span class="attribute">order</span>:<span class="number">0</span>;</span><br><span class="line">    <span class="attribute">flex</span>:<span class="number">0</span> <span class="number">1</span> auto;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<h3 id="order属性定义项目的排列顺序。数值越小，排列越靠前，默认为0。"><a href="#order属性定义项目的排列顺序。数值越小，排列越靠前，默认为0。" class="headerlink" title="order属性定义项目的排列顺序。数值越小，排列越靠前，默认为0。"></a>order属性定义项目的排列顺序。数值越小，排列越靠前，默认为0。</h3><h3 id="flex属性是flex-grow（放大比例）-flex-shrink-（缩小比例）和-flex-basis（所占主轴宽度比例-）的简写。"><a href="#flex属性是flex-grow（放大比例）-flex-shrink-（缩小比例）和-flex-basis（所占主轴宽度比例-）的简写。" class="headerlink" title="flex属性是flex-grow（放大比例）, flex-shrink （缩小比例）和 flex-basis（所占主轴宽度比例%）的简写。"></a>flex属性是flex-grow（放大比例）, flex-shrink （缩小比例）和 flex-basis（所占主轴宽度比例%）的简写。</h3><ul>
<li>配合媒体查询更改<code>flex:1 1 50%;</code>里的百分比实现响应式</li>
</ul>

    </div>
    
    <div class="post-footer">
        <div>
            
            转载声明：
            商业转载请联系作者获得授权,非商业转载请注明出处 © <a href="" target="_blank">Snippet</a>
            
            
        </div>
        <div>
            
        </div>
    </div>
</article>
<div class="article-nav prev-next-wrap clearfix">
    
    <a href="/blog/2019/10/05/前端开发中79条不可忽视的知识点汇总/" class="pre-post btn btn-default" title='前端开发中79条不可忽视的知识点汇总'>
        <i class="fa fa-angle-left fa-fw"></i><span class="hidden-lg">上一篇</span>
        <span class="hidden-xs">
            前端开发中79条不可忽视的知识点汇总</span>
    </a>
    
    
    <a href="/blog/2019/09/27/利用keep-alive实现vue页面返回记住滚动条上次浏览位置/" class="next-post btn btn-default" title='利用 keep-alive 实现vue页面返回记住滚动条上次浏览位置'>
        <span class="hidden-lg">下一篇</span>
        <span class="hidden-xs">
            利用 keep-alive 实现vue页面返回记住滚动条上次浏览位置</span><i class="fa fa-angle-right fa-fw"></i>
    </a>
    
</div>

                </main>
                
                    <aside id="article-toc" role="navigation" class="col-md-4">
    <div class="widget">
        <h3 class="title">
            文章目录
        </h3>
        
        <ol class="toc"><li class="toc-item toc-level-2"><a class="toc-link" href="#父容器属性"><span class="toc-text">父容器属性</span></a><ol class="toc-child"><li class="toc-item toc-level-3"><a class="toc-link" href="#flex-flow：主轴方向flex-direction和换行方式flex-wrap的缩写形式"><span class="toc-text">flex-flow：主轴方向flex-direction和换行方式flex-wrap的缩写形式</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#justify-content：主轴设置，即项目水平方向位置"><span class="toc-text">justify-content：主轴设置，即项目水平方向位置</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#align-items：侧轴设置，即项目垂直方向位置"><span class="toc-text">align-items：侧轴设置，即项目垂直方向位置</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#align-content：当项目换为多行时，即用align-content取代align-items，值同-justify-content"><span class="toc-text">align-content：当项目换为多行时，即用align-content取代align-items，值同 justify-content</span></a></li></ol></li><li class="toc-item toc-level-2"><a class="toc-link" href="#子项目属性"><span class="toc-text">子项目属性</span></a><ol class="toc-child"><li class="toc-item toc-level-3"><a class="toc-link" href="#order属性定义项目的排列顺序。数值越小，排列越靠前，默认为0。"><span class="toc-text">order属性定义项目的排列顺序。数值越小，排列越靠前，默认为0。</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#flex属性是flex-grow（放大比例）-flex-shrink-（缩小比例）和-flex-basis（所占主轴宽度比例-）的简写。"><span class="toc-text">flex属性是flex-grow（放大比例）, flex-shrink （缩小比例）和 flex-basis（所占主轴宽度比例%）的简写。</span></a></li></ol></li></ol>
        
    </div>
</aside>
                
            </div>
        </div>
    </section>
    <footer class="main-footer">
    <div class="container">
        <div class="row">
        </div>
    </div>
</footer>
<a id="back-to-top" class="icon-btn hide">
    <i class="fa fa-chevron-up"></i>
</a>
    <div class="copyright">
    <div class="container">
        <div class="row">
            <div class="col-sm-12">
                <div class="busuanzi">
    
</div>
            </div>
            <div class="col-sm-12">
                <span>Copyright &copy;
                    2017
                </span> |
                <span>
                    Powered by <a href="//hexo.io" class="copyright-links" target="_blank" rel="nofollow">Hexo</a>
                </span> |
                <span>
                    Theme by <a href="//github.com/shenliyang/hexo-theme-snippet.git" class="copyright-links" target="_blank" rel="nofollow">Snippet</a>
                </span>
            </div>
        </div>
    </div>
</div>



<script src="/blog/js/app.js?rev=@@hash"></script>
</body>
</html>